<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数组案例</title>
</head>
<body>
    <script>
    // 把数组中的 0 去掉，其余的存入新的数组并输出。
    var arr=[10, 0, 20, 0, 30, 0, 40, 0, 50];
    var newArr =[];
    for (var i=0; i<arr.length; i++){
        if(arr[i]!=0){
            newArr[newArr.length] = arr[i];
        }
    }
    
    console.log(newArr);

    </script>
</body>
</html>